// using Gio;

namespace Vwf.Vwt {
	class vwt2vala {
		public static int main(string[] args) {
			string src = loadTextFile(args[1]);
			var parser = Parser.getStartParser(src);
			try {
				parser.parse();
				stdout.printf("\tpublic void init() {\n");
				stdout.printf(parser.content.codeInit());
				stdout.printf("\tpublic void preRender() {\n");
				stdout.printf(parser.content.codePreRender());
				stdout.printf("\tpublic void render() {\n");
				stdout.printf(parser.content.codeRender());
			} catch (EDParser err) {
				if (err is EDParser.UnexpectedEOF) {
					stderr.printf("UnexpectedEOF");
 				} else if (err is EDParser.ParserClassNotExists) {
					stderr.printf("ParserClassNotExists");
 				} else if (err is EDParser.UnknownBlock) {
					stderr.printf("UnknownBlock");
 				}
				// stderr.printf(err.get_type().name() + ": " + err.message + "\n");
				
				stderr.printf("#" + parser.strParser.lineNum.to_string() + "," + parser.strParser.colNum.to_string() + ": ");
			};
			
			return 0;
		}
		public static string loadTextFile(string fileName) {
			string text = "";
			var file = File.new_for_path (fileName);
			var dis = new DataInputStream (file.read ());
			string line = "";
			while ((line = dis.read_line (null)) != null) {
				text += line + "\n";
			}
			
			return text;
		}
	}
}
